home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / codecs / mccomponent / hidemenubar.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  3.1 KB  |  120 lines

  1. /*
  2.     File:        HideMenuBar.c
  3.  
  4.     Contains:    code snippet for hiding menu bar.
  5.  
  6.     Written by: John Wang    
  7.  
  8.     Copyright:    Copyright © 1994-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 8/18/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 03/14/94    JW                Re-Created for Universal Headers.
  21.  
  22. */
  23.  
  24. #ifdef THINK_C
  25. #define        applec
  26. #endif
  27.  
  28. #include    <Memory.h>
  29. #include    <QuickDraw.h>
  30. #include    <LowMem.h>
  31.  
  32. #include    "HideMenuBar.h"
  33.  
  34. typedef struct    {                        
  35.     short                oldMBarHeight;
  36.     RgnHandle            theBarRgn;
  37. } MenuBarGlobals;
  38.  
  39. /* ------------------------------------------------------------------------- */
  40.  
  41. /*
  42.     Description:    Call this routine to hide menu bar.
  43.  
  44.     Format Params:    
  45.         Name            Usage    Description/Assumptions
  46.         ----            ----    -----------------------
  47.         return            R        Returns a handle that must be passed back to RestoreMenuBar().
  48.                 
  49.     Usage: P=Parameter,R=ReturnValue,E=External,G=FileGlobal,L=Local,I=Input,O=Output
  50.     
  51.     Error Handling:    Return nil if failed.
  52.  
  53.     Special Notes:    xxx put other comments here xxx
  54.  
  55. */
  56.  
  57. Handle MyHideMenuBar()
  58. {
  59.     Rect                mBarRect;
  60.     RgnHandle            mBarRgn;
  61.     MenuBarGlobals        **myHandle;
  62.     Rect                myMainDeviceRect;
  63.     
  64.     myHandle = (MenuBarGlobals **) NewHandleClear(sizeof(MenuBarGlobals));
  65.     if ( myHandle == nil )
  66.         goto bail;
  67.         
  68.     myMainDeviceRect = (**GetMainDevice()).gdRect;
  69.     
  70.     (**myHandle).oldMBarHeight = GetMBarHeight();
  71.     LMSetMBarHeight(0);
  72.     SetRect(&mBarRect, myMainDeviceRect.left, myMainDeviceRect.top,
  73.             myMainDeviceRect.right, myMainDeviceRect.top + (**myHandle).oldMBarHeight);
  74.     mBarRgn = NewRgn();
  75.     RectRgn(mBarRgn, &mBarRect);
  76.     UnionRgn(LMGetGrayRgn(), mBarRgn, LMGetGrayRgn());
  77.     (**myHandle).theBarRgn = mBarRgn;
  78.     
  79. bail:
  80.     return( (Handle) myHandle );
  81. }
  82.  
  83. /* ------------------------------------------------------------------------- */
  84.  
  85. /*
  86.     Description:    Call this routine to restore menu bar.
  87.  
  88.     Format Params:    
  89.         Name            Usage    Description/Assumptions
  90.         ----            ----    -----------------------
  91.         theHandle        PI        Contains info to restore menu bar.
  92.                 
  93.     Usage: P=Parameter,R=ReturnValue,E=External,G=FileGlobal,L=Local,I=Input,O=Output
  94.     
  95.     Error Handling:    If passed nil handle, then just quit.
  96.  
  97.     Special Notes:    xxx put other comments here xxx
  98.  
  99. */
  100.  
  101. void RestoreMenuBar(Handle theHandle)
  102. {
  103.     RgnHandle            mBarRgn;
  104.     MenuBarGlobals        **myHandle;
  105.     
  106.     if (theHandle == nil)
  107.         goto bail;
  108.     myHandle = (MenuBarGlobals **) theHandle;
  109.         
  110.     //    Restore menu bar.
  111.     LMSetMBarHeight((**myHandle).oldMBarHeight);
  112.     mBarRgn = (**myHandle).theBarRgn;
  113.     DiffRgn(LMGetGrayRgn(), mBarRgn, LMGetGrayRgn());
  114.     DisposeRgn(mBarRgn);
  115.     DrawMenuBar();
  116.     
  117. bail:
  118.     if (theHandle != nil)
  119.         DisposeHandle(theHandle);
  120. }